/****************本js文件主要用于表格的查询********************/

// 上下文环境
let ctxPath = '';

// 搜索信息，展开，收起
$('legend').click(function () {
    $('#search-form').slideToggle('1000');
});

// 显示搜索条件
$('body').on('click', '.search-show', function () {
    $('body .search-box').show();
    $('body .search-show').hide();
    $('body .search-hide').show();
});

// 隐藏搜索条件
$('body').on('click', '.search-hide', function () {
    $('body .search-box').hide();
    $('body .search-show').show();
    $('body .search-hide').hide();
});

//layui 开始日期时间格式化
function startDateTimeFormat(dateObj) {
    let FullYear = dateObj.year;
    let Month = dateObj.month;
    let Day = dateObj.date;
    return FullYear + "-" + (Month >= 10 ? Month : "0"+Month) + "-" + (Day >= 10 ? Day : "0"+Day) + " 00:00:00";
}

//layui 结束日期时间格式化
function endDateTimeFormat(dateObj) {
    let FullYear = dateObj.year;
    let Month = dateObj.month;
    let Day = dateObj.date;
    return FullYear + "-" + (Month >= 10 ? Month : "0"+Month) + "-" + (Day >= 10 ? Day : "0"+Day) + " 23:59:59";
}
//layui 开始日期时间格式化,返回紧促格式
function startDateTimeFormatStr(dateObj) {
    let FullYear = dateObj.year;
    let Month = dateObj.month;
    let Day = dateObj.date;
    return FullYear + "" + (Month >= 10 ? Month : "0"+Month) + "" + (Day >= 10 ? Day : "0"+Day) + "000000";
}

//layui 结束日期时间格式化,返回紧促格式
function endDateTimeFormatStr(dateObj) {
    let FullYear = dateObj.year;
    let Month = dateObj.month;
    let Day = dateObj.date;
    return FullYear + "" + (Month >= 10  ? Month : "0"+Month) + "" + (Day >= 10  ? Day : "0"+Day) + "235959";
}

//layui 计算时间差
function diffDays(startDateObj,endDateObj) {
    let FullYear1 = startDateObj.year;
    let Month1 = startDateObj.month;
    let Day1 = startDateObj.date;

    let FullYear2 = endDateObj.year;
    let Month2 = endDateObj.month;
    let Day2 = endDateObj.date;

    let startDate = new Date(FullYear1 + "-" + Month1 + "-" + Day1);
    let endDate = new Date(FullYear2 + "-" + Month2 + "-" + Day2);
    let times = endDate.getTime() - startDate.getTime();

    return parseInt(times / (1000 * 60 * 60 * 24));
}

//复制内容
function copy(text){
    let textarea = document.createElement('textarea');
    textarea.value = text;
    textarea.style.position = 'absolute';
    textarea.style.opacity = '0';
    document.body.appendChild(textarea);
    textarea.select();
    let copied = false;
    try{
        copied = document.execCommand('copy');
    }catch(err){
        console.log('error', err);
    }
    textarea.remove();
    return copied;
}